package com.Maykk.Demo07;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName: SaveToFile
 * @Description: TODO TCP 接收客户端数据并写入文件
 * @Author: MaykkStar@163.com
 */
public class SaveToFile {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9527);
        Socket socket = serverSocket.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        BufferedWriter bw = new BufferedWriter(new FileWriter("TCP_IO.txt"));
        String line;
        while (!(line = br.readLine()).equals("")) {
            bw.write(line + "\n");
            bw.flush();
            System.out.println("保存到文件 > " + line);
        }

        serverSocket.close();
    }
}
